<?php

/*
Scheduled Tasks (admin_tasks.php)
*/

$page_title = "Scheduled Tasks";
$rank_check = 7;
include "../header.inc.php";

print "$openHTML";

$game=$_GET['game'];
$act=$_GET['act'];
$task=$_GET['task'];

if($act=="delete")
{
	mysql_query("Delete from ghetto_cron where game = '$game' and id= '$task'");
	die(header(error("admin_tasks.php?game=$game","The specified task has been deleted!")));
}
elseif($act=="edit")
{
}
else
{
	$act = "create";
}
ECHO <<<END

<FORM ACTION="admin_tasks.pro.php?game=$game&act=create" METHOD=POST>

<p><b>CREATE A TASK:</b></p>

<p>Add Task Type: <select name=task_type>
<option value="Low Stock" >Low Shop Stock
<option value="Medium Stock" >Medium Shop Stock
<option value="Full Stock" >Full Shop Stock
<option value="Lower Pet Attitude" >Lower Pet Attitude
<option value="Lower Pet Hunger" >Lower Pet Hunger
<option value="Lower User Hunger" >Lower User Hunger
<option value="End Penny Play" >End Penny Play
<option value="End Referral Contest" >End Referral Contest
<option value="End Daily Lotto" >End Daily Lotto
</select><br>
Run it at: <input type=text name=task_hour size=5 value=00>:<input type=text name=task_minutes size=5 value=00><select name=am_pm><option value="0" >A. M.<option value="12" >P. M.</select><br>
ONLY Run on the <select name=monthly_run>
<option value="">None
<option value=1>1st
<option value=2>2nd
<option value=3>3rd
<option value=4>4th
<option value=5>5th
<option value=6>6th
<option value=7>7th
<option value=8>8th
<option value=9>9th
<option value=10>10th
<option value=11>11th
<option value=12>12th
<option value=13>13th
<option value=14>14th
<option value=15>15th
<option value=16>16th
<option value=17>17th
<option value=18>18th
<option value=19>19th
<option value=20>20th
<option value=21>21st
<option value=22>22nd
<option value=23>23rd
<option value=24>24th
<option value=25>25th
<option value=26>26th
<option value=27>27th
<option value=28>28th
<option value=29>29th
<option value=30>30th
<option value=31>31st
</select> of the month. (optional for monthly runs)<br>
ONLY Run on <select name=weekly_run>
<option value="">None
<option value=1>Sundays
<option value=2>Mondays
<option value=3>Tuesdays
<option value=4>Wednesdays
<option value=5>Thursdays
<option value=6>Fridays
<option value=7>Saturdays
</select> (optional for weekly runs)<br>
Add this Update: (only fill out if you want it to add an update.)<Br>
<TEXTAREA NAME=add_update ROWS=7 COLS=27 WRAP=virtual></TEXTAREA><br>
<input type=submit value="Create Task">

</FORM>

END;

$x = 1;
$findTasks = mysql_query("SELECT * FROM ghetto_cron WHERE game = '$game'");
while ($getTasks = mysql_fetch_array($findTasks))
{
	$id = $getTasks[id];
	$explodeCronTime = explode(":", $getTasks[cron_time]);
	$cronHour  = $explodeCronTime[0];
	$cronMin   = $explodeCronTime[1];
	if ($cronHour > 12) { $cronAMPM = "P. M."; $cronHour -= 12; } else { $cronAMPM = "A. M."; }
	$getTasks[cron_time] = "$cronHour:$cronMin $cronAMPM";
	
	if ($getTasks[last_run])
	{
		$getTasks[last_run] = date("g:i:s, M j",$getTasks[last_run]);
	}
	else
	{
		$getTasks[last_run] = "<i>never</i>";
	}
	if ($getTasks[add_update])
	{
		$addUpdateLine[$id] = "<Br>Add Update: $getTasks[add_update]";
	}
	
	print "<p><b>$x. $getTasks[cron_name]</b> - <a href=admin_edit_tasks.php?game=$game&act=edit&task=$getTasks[id]>Edit</a>, <a href=admin_tasks.php?game=$game&act=delete&task=$getTasks[id]><font color=red>Delete</font></A><br>
	Next Run at: $getTasks[cron_time]<Br>
	Last Run at: $getTasks[last_run]<br>
	Total Runs: $getTasks[total_runs]
	$addUpdateLine[$id]</p>";
	
	$x++;
}


print "$closeHTML";
?>
